<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="订单ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orderId">
              <a-input v-model="model.orderId" placeholder="请输入订单ID"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="展会ID" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="exhibitionId">
              <j-dict-select-tag type="list" v-model="model.exhibitionId" dictCode="" placeholder="请选择展会ID" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="展会主办方" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="organizer">
              <a-input v-model="model.organizer" placeholder="请输入展会主办方"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="下单时展会主图" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="cover">
              <a-input v-model="model.cover" placeholder="请输入下单时展会主图"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="会议名称" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="name">
              <a-input v-model="model.name" placeholder="请输入会议名称"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报名费（单票价格）" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="applyCost">
              <a-input-number v-model="model.applyCost" placeholder="请输入报名费（单票价格）" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="购票数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="quantity">
              <a-input-number v-model="model.quantity" placeholder="请输入购票数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="订单状态：0-已取消;1-待付款;2-待发货;3-待收货;4-已完成" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="status">
              <a-input-number v-model="model.status" placeholder="请输入订单状态：0-已取消;1-待付款;2-待发货;3-待收货;4-已完成" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="会议地址" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fullAddress">
              <a-textarea v-model="model.fullAddress" rows="4" placeholder="请输入会议地址" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报名联系人电话" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contactPhone">
              <a-input v-model="model.contactPhone" placeholder="请输入报名联系人电话"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="报名联系人" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contactPerson">
              <a-input v-model="model.contactPerson" placeholder="请输入报名联系人"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="逻辑删除：1表示删除，0表示未删除。" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="isDeleted">
              <a-input-number v-model="model.isDeleted" placeholder="请输入逻辑删除：1表示删除，0表示未删除。" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'HTOrderExhibitionForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           orderId: [
              { required: true, message: '请输入订单ID!'},
           ],
           exhibitionId: [
              { required: true, message: '请输入展会ID!'},
           ],
           organizer: [
              { required: true, message: '请输入展会主办方!'},
           ],
           cover: [
              { required: true, message: '请输入下单时展会主图!'},
           ],
           name: [
              { required: true, message: '请输入会议名称!'},
           ],
           // applyCost: [
           //    { required: true, message: '请输入报名费（单票价格）!'},
           // ],
           quantity: [
              { required: true, message: '请输入购票数量!'},
           ],
           status: [
              { required: true, message: '请输入订单状态：0-已取消;1-待付款;2-待发货;3-待收货;4-已完成!'},
           ],
           fullAddress: [
              { required: true, message: '请输入会议地址!'},
           ],
           contactPhone: [
              { required: true, message: '请输入报名联系人电话!'},
           ],
           contactPerson: [
              { required: true, message: '请输入报名联系人!'},
           ],
        },
        url: {
          add: "/industry/hTOrderExhibition/add",
          edit: "/industry/hTOrderExhibition/edit",
          queryById: "/industry/hTOrderExhibition/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }

        })
      },
    }
  }
</script>
